<?php
// +----------------------------------------------------------------------
// | 一机一码 [ 公众号和小程序运营管理系统 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017 http://www.bctos.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: huajie <banhuajie@163.com>
// +----------------------------------------------------------------------

namespace app\admin\controller;

/**
 * 行为控制器
 * @author huajie <banhuajie@163.com>
 */
class Action extends Admin {

    /**
     * 行为日志列表
     * @author huajie <banhuajie@163.com>
     */
    public function actionLog(){
        //获取列表数据
        $map['status']    =   array('>', -1);
        $list   =   $this->lists_data('ActionLog', $map);
        int_to_string($list);
        foreach ($list as $key=>$value){
            $model_id                  =   get_document_field($value['model'],"name","id");
            $list[$key]['model_id']    =   $model_id ? $model_id : 0;
        }
        $this->assign('_list', $list);
        $this->meta_title = '行为日志';
        return $this->fetch();
    }

    /**
     * 查看行为日志
     * @author huajie <banhuajie@163.com>
     */
    public function edit($id = 0){
        if(empty($id))
           return $this->error('参数错误！');

        $info = M( 'ActionLog' )->field(true)->where('id', $id)->find();

        $this->assign('info', $info);
        $this->meta_title = '查看行为日志';
        return $this->fetch();
    }

    /**
     * 删除日志
     * @param mixed $ids
     * @author huajie <banhuajie@163.com>
     */
    public function remove($ids = 0){
        if(empty($ids))
           return  $this->error('参数错误！');
       
        $res = M( 'ActionLog' )->whereIn ( 'id', $ids )->delete();
        if($res !== false){
            return $this->success('删除成功！');
        }else {
            return $this->error('删除失败！');
        }
    }

    /**
     * 清空日志
     */
    public function clearCache(){
        $res = M( 'ActionLog' )->where( '1=1')->delete();
        if($res !== false){
            return $this->success('日志清空成功！');
        }else {
            return $this->error('日志清空失败！');
        }
    }

}
